package com.fengye.middleware.rabbitmq.boot.demo.basic;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 *
 * @author sky
 * @date 2021年06月09日 11:06 上午
 */
@Component
public class BasicConfig {

    @Value("${mq.basic.info.queue.name:basic_queue_name}")
    private String basicQueueName;

    @Value("${mq.basic.info.exchange.name:basic_change_name}")
    private String basicExchangeName;

    @Value("${mq.basic.info.routing.key.name:basic_routing_key_name}")
    private String basicRoutingKeyName;

    /* 创建简单消息模型：队列、交换机和路由 */

    // 队列
    @Bean(name = "basicQueue")
    public Queue basicQueue() {
        return new Queue(basicQueueName);
    }

    @Bean(name = "basicExchange")
    public DirectExchange basicExchange() {
        return new DirectExchange(basicExchangeName, true, false);
    }

    @Bean
    public Binding basicBinding(@Qualifier("basicQueue") Queue basicQueue, @Qualifier("basicExchange") DirectExchange basicExchange) {
        return BindingBuilder.bind(basicQueue).to(basicExchange).with(basicRoutingKeyName);
    }


}
